<?php
/**
 * DotHerbert
 *
 * @package    unittest
 * @copyright  2009 extreme-programmers
 * @license    http://dotherbert.extreme-programmers.com/license   BSD License
 * @version    $Id:$
 */

namespace dotherbert\unittest;
use dotherbert\core\stub;

/**
 * Layer testcase
 *
 * @package    unittest
 * @author     Johannes Trink <johannes.trink@extreme-programmers.com>
 */
abstract class LayerTestCase extends TestCase
{
    /**
     * Application
     *
     * @var \Zend_Application
     */
    private $application;

    /**
     * Set application
     *
     * @param \Zend_Application $application
     * @return void
     */
    public function setApplication(\Zend_Application $application)
    {
        $this->application = $application;
    }

    /**
     * Get application
     *
     * @return \Zend_Application
     */
    public function getApplication()
    {
        return $this->application;
    }

    /**
     * Reset
     *
     * @return void
     */
    public function reset()
    {
    }

    /**
     * Bootstrap application
     *
     * @return void
     */
    public function bootstrapApplication($module, $service)
    {
        $miscStub = stub\MiscStub::getInstance();

        $config = new \Zend_Config_Ini(implode(DIRECTORY_SEPARATOR,
                                               array($miscStub->constant('APPLICATION_PATH'),
                                                     'configs', 'service.ini')), 'testing', true);
        $config->config = implode(DIRECTORY_SEPARATOR,
                                  array($miscStub->constant('MODULES_PATH'),
                                        $module, $service . '.ini'));
        $config->setReadonly();
        $this->setApplication(new \Zend_Application('testing', $config));
    }

    /**
     * Bootstrap
     *
     * @param string $module
     * @return void
     */
    public function bootstrap($module, $service)
    {
        $this->reset();
        $this->bootstrapApplication($module, $service);
    }
}